package logic

import (
	"campus-trade/models/mysql"
	"context"

	"campus-trade/campusrpc/campusrpc"
	"campus-trade/campusrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BooklistLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBooklistLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BooklistLogic {
	return &BooklistLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BooklistLogic) Booklist(in *campusrpc.BooklistRequest) (*campusrpc.BooklistResponse, error) {
	// todo: add your logic here and delete this line

	var ubc []mysql.UserBookClass
	mysql.DB.Debug().Model(&mysql.User{}).
		Select("users.*,books.name as book_name,classes.name as classes_name").
		Joins("left join books on book.id = user.book_id").
		Joins("left join classes on classes.id = user.class_id").
		Find(&ubc)

	return &campusrpc.BooklistResponse{}, nil
}
